/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rc4;

/**
 *
 * @author Giorgio
 */
public class Main {

    
    /**
     * @param args the command line arguments
     *
     */
    public static void main(String[] args) throws Exception {
        /*Initialize idSlave with given argument*/
        long groupId = 0; /*The current */
        int nbKeyPerGroup = 0; /*the number of key per group*/
         long keyId; /*id reprensenting the first key tried*/

        if (args.length > 0) {
            try {
                groupId = Long.parseLong(args[0]);
                nbKeyPerGroup = Integer.parseInt(args[1]);
            } catch (NumberFormatException e) {
                System.err.println("Argument must be an integer");
                System.exit(1);
            }
        }
        
        /*Defining the first and last letter of the key*/
        keyId = groupId * nbKeyPerGroup;
        /*keyId = (82L-33L)+
                (48L-33L)*94L+
                (87L-33L)*94L*94L+
                (78L-33L)*94L*94L*94L+
                (51L-33L)*94L*94L*94L*94L+
                (68L-33L)*94L*94L*94L*94L*94L+
                (49L-33L)*94L*94L*94L*94L*94L*94L+
                (72L-33L)*94L*94L*94L*94L*94L*94L*94L;*/
        /*Launch brut force algorithm*/
        RC4 rc4checker= new RC4();

        System.out.println("Job processing the "+groupId+" group of "+ nbKeyPerGroup+" keys !");
        System.out.println("This group start with the key '"+rc4checker.generateKey(keyId)+"'" );
         System.out.println("and finish with the key '"+rc4checker.generateKey(keyId+nbKeyPerGroup-1)+"'" );
        StringBuffer result = new StringBuffer();
        if(rc4checker.brutForceRC4(keyId, nbKeyPerGroup, result))
        {
            System.out.println("Key is found: "+result);
        }else
        {
            System.out.println("No key was found!");
        }
    }


}
